//
//  ListTableViewController.m
//  9-20
//
//  Created by mac on 16/9/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ListTableViewController.h"
#import "SearchresController.h"
@interface ListTableViewController ()<UISearchResultsUpdating,UISearchControllerDelegate>

@property (strong,nonatomic)UISearchController *searchCon;
@property (strong,nonatomic)NSArray *arr;
@end

@implementation ListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.arr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"2",@"1",nil];
    
    self.searchCon = [[UISearchController alloc] initWithSearchResultsController:[self.storyboard instantiateViewControllerWithIdentifier:@"searchres"]];
    self.searchCon.searchResultsUpdater = self;
    self.searchCon.delegate = self;
    self.definesPresentationContext = YES;
    self.tableView.tableHeaderView = self.searchCon.searchBar;
}

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
    SearchresController *serchres = (SearchresController *)searchController.searchResultsController;
    serchres.muarr = [NSMutableArray new];
    for(NSString *str in self.arr)
    {
        if([str isEqualToString:self.searchCon.searchBar.text])
        {
           // NSLog(@"%@",str);
            [serchres.muarr addObject:str];
        }
    }
    
    //NSLog(@"%@",serchres.muarr);
    [serchres.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
